home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / windows4 / plx17.zip / TEXTSTRM.PAS < prev    next >
Pascal/Delphi Source File  |  1992-06-14  |  3KB  |  125 lines

  1. {TextStrm - Extensions to ObjectWindows Copyright (C) Doug Overmyer 7/1/91}
  2. unit TextStrm;
  3. {**********************  Interface  *************************}
  4. interface
  5. uses WinTypes, WinProcs, WinDos, Strings, WObjects,WFPlus;
  6. type
  7. PTextStream = ^TTextStream ;
  8. TTextStream = object(TBufStream)
  9.    CharsToRead : LongInt;
  10.    CharsRead : LongInt;
  11.    ARecord :PChar;
  12.    constructor Init(FileName:PChar;Mode,Size:Word);
  13.    destructor Done;virtual;
  14.    function GetNext:PChar;virtual;
  15.    function WriteNext(szARecord:PChar):integer;virtual;
  16.    function WriteEOF:integer;virtual;
  17.    function IsEOF:Boolean;virtual;
  18.    function GetPctDone:Integer;
  19. end;
  20.  
  21. {************************  Implementation        ********************}
  22. implementation
  23. {************************  TTextStream         **********************}
  24. constructor TTextStream.Init(FileName:PChar; Mode,Size:Word);
  25. begin
  26.     TBufStream.Init(FileName,Mode,Size);
  27.   CharsRead := 0;
  28.   CharsToRead := TBufStream.GetSize;
  29.   ARecord := MemAlloc(32000);
  30. end;
  31.  
  32. destructor TTextStream.Done;
  33. begin
  34.     TBufStream.Done;
  35.   FreeMem(ARecord,32000);
  36. end;
  37.  
  38. {replace unwanted control chars with spaces 10/5/91}
  39. function TTextStream.GetNext:PChar;
  40. var
  41.     Blksize:Integer;
  42.   AChar:Char;
  43.   Indx : Integer;
  44.   IsEOR : Boolean;
  45. begin
  46.     Indx := 0;
  47.   IsEOR := False;
  48.   ARecord[0] := #0;
  49.   while (CharsRead < CharsToRead) and (IsEOR = False) do
  50.       begin
  51.       TBufStream.Read(AChar,1);
  52.     Inc(CharsRead);
  53.     case AChar of
  54.       #13:
  55.           begin
  56.         ARecord[Indx] := #0;
  57.         IsEOR := True;
  58.         end;
  59.         #26:
  60.           begin
  61.         if Indx > 0 then
  62.             begin
  63.           ARecord[Indx] := #0;
  64.           IsEOR := True;
  65.           end;
  66.         end;
  67.       #10:
  68.           begin
  69.         end;
  70.       #9:
  71.           begin
  72.         ARecord[Indx] := AChar;
  73.         Inc(Indx);
  74.         end;
  75.       #0..#31:
  76.           begin
  77.         ARecord[Indx] := ' ';
  78.         Inc(Indx);
  79.         end;
  80.       else
  81.           begin
  82.         ARecord[Indx] := AChar;
  83.         inc(Indx);
  84.         end;
  85.     end;
  86.   end;
  87.   ARecord[Indx] := #0;
  88.   GetNext := ARecord;
  89. end;
  90.  
  91. {This method not actually used due to performance loss - instead
  92.    TStream.Write is called directly}
  93. function TTextStream.WriteNext(szARecord:PChar):Integer;
  94. const
  95.   CRLF : Array[0..2] of Char = #13#10#0;
  96. begin
  97.     TBufStream.Write(szARecord,
  98.     StrLen(szARecord));
  99.     TBufStream.Write(CRLF,2);
  100.     WriteNext := StrLen(szARecord);
  101. end;
  102.  
  103. function TTextStream.WriteEOF:Integer;
  104. const
  105.       EOF : Array[0..1] of Char  = #26;
  106. begin
  107.     TBufStream.Write(EOF,1);
  108.    WriteEOF := 1;
  109. end;
  110.  
  111. function TTextStream.IsEOF:Boolean;
  112. begin
  113.     IsEOF := False;
  114.     if CharsRead >= CharsToRead then
  115.        IsEOF := True;
  116. end;
  117.  
  118. function TTextStream.GetPctDone:Integer;
  119. begin
  120.     GetPctDone := CharsRead*100 div CharsToRead;
  121. end;
  122.  
  123.  
  124. end.
  125.